package com.norbitltd.guavaleaves.java.util;

import java.util.Calendar;

import org.apache.commons.lang3.time.DateUtils;

import com.google.common.base.Predicate;

public class CalendarPredicates {
	
	/**
	 * @see org.apache.commons.lang3.time.CalendarUtils.isSameDay
	 */
	public Predicate<Calendar> isSameDay(final Calendar d) {
		return new Predicate<Calendar>() {
			public boolean apply(Calendar input) {
				return DateUtils.isSameDay(input, d);
			}	
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.CalendarUtils.isSameInstant
	 */
	public Predicate<Calendar> isSameInstant(final Calendar d) {
		return new Predicate<Calendar>() {
			public boolean apply(Calendar input) {
				return DateUtils.isSameInstant(input, d);
			}
		};
	}
	
	/**
	 * @see org.apache.commons.lang3.time.CalendarUtils.truncatedEquals
	 */
	public Predicate<Calendar> truncatedEquals(final Calendar d, final int field) {
		return new Predicate<Calendar>() {
			public boolean apply(Calendar input) {
				return DateUtils.truncatedEquals(input, d, field);
			}
		};
	}
	
	/**
	 * @see java.util.Calendar.after
	 */
	public Predicate<Calendar> after(final Calendar d) {
		return new Predicate<Calendar>() {
			public boolean apply(Calendar input) {
				return input.after(d);
			}
		};
	}
	
	/**
	 * @see java.util.Calendar.before
	 */
	public Predicate<Calendar> before(final Calendar d) {
		return new Predicate<Calendar>() {
			public boolean apply(Calendar input) {
				return input.before(d);
			}
		};
	}
}
